package com.ruoyan.config;

import com.ruoyan.pojo.User;
import com.ruoyan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Package: com.ruoyan.conifg
 * @ClassName: LoginHandlerInterceptor
 * @Author: ruoyan1998
 * @CreateTime: 2021/5/16 14:33
 * @Description: 登录拦截器
 */
public class LoginHandlerInterceptor implements HandlerInterceptor
{
    @Autowired
    UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
    {
        Object user = request.getSession().getAttribute("user");

        if(user == null)
        {
            request.setAttribute("msg","无访问权限，请先登录");
            request.getRequestDispatcher("/index").forward(request,response);
            return false;
        }

        return true;

    }
}
